

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.nn.ActQuant &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="mindspore.nn.Conv2dBnAct" href="mindspore.nn.Conv2dBnAct.html" />
    <link rel="prev" title="mindspore.nn.MaxPool2d" href="mindspore.nn.MaxPool2d.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../mindspore.nn.html">mindspore.nn</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id1">基本构成单元</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id2">容器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id3">卷积层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id4">梯度</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id5">循环层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id6">稀疏层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id7">非线性激活函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id8">工具</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id9">图像</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id10">归一化层</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id11">池化层</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../mindspore.nn.html#id12">量化</a><ul class="current">
<li class="toctree-l3 current"><a class="current reference internal" href="#">mindspore.nn.ActQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnAct.html">mindspore.nn.Conv2dBnAct</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnFoldQuant.html">mindspore.nn.Conv2dBnFoldQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnFoldQuantOneConv.html">mindspore.nn.Conv2dBnFoldQuantOneConv</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dBnWithoutFoldQuant.html">mindspore.nn.Conv2dBnWithoutFoldQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.Conv2dQuant.html">mindspore.nn.Conv2dQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.DenseBnAct.html">mindspore.nn.DenseBnAct</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.DenseQuant.html">mindspore.nn.DenseQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.FakeQuantWithMinMaxObserver.html">mindspore.nn.FakeQuantWithMinMaxObserver</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.MulQuant.html">mindspore.nn.MulQuant</a></li>
<li class="toctree-l3"><a class="reference internal" href="mindspore.nn.TensorAddQuant.html">mindspore.nn.TensorAddQuant</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id13">损失函数</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id14">优化器</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#wrapper">Wrapper</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id15">数学运算</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id16">评估指标</a></li>
<li class="toctree-l2"><a class="reference internal" href="../mindspore.nn.html#id17">动态学习率</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../mindspore.nn.html">mindspore.nn</a> &raquo;</li>
        
      <li>mindspore.nn.ActQuant</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
          
            <a href="../../_sources/api_python/nn/mindspore.nn.ActQuant.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="mindspore-nn-actquant">
<h1>mindspore.nn.ActQuant<a class="headerlink" href="#mindspore-nn-actquant" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="mindspore.nn.ActQuant">
<em class="property">class </em><code class="sig-prename descclassname">mindspore.nn.</code><code class="sig-name descname">ActQuant</code><span class="sig-paren">(</span><em class="sig-param">activation</em>, <em class="sig-param">ema=False</em>, <em class="sig-param">ema_decay=0.999</em>, <em class="sig-param">fake_before=False</em>, <em class="sig-param">quant_config=quant_config_default</em>, <em class="sig-param">quant_dtype=QuantDtype.INT8</em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/mindspore/nn/layer/quant.html#ActQuant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#mindspore.nn.ActQuant" title="Permalink to this definition">¶</a></dt>
<dd><p>Quantization aware training activation function.</p>
<p>Add the fake quantized operation to the end of activation operation, by which the output of activation
operation will be truncated. For more details about Quantization, please refer to the implementation
of subclass of <cite>FakeQuantWithMinMaxObserver</cite>, <a class="reference internal" href="mindspore.nn.FakeQuantWithMinMaxObserver.html#mindspore.nn.FakeQuantWithMinMaxObserver" title="mindspore.nn.FakeQuantWithMinMaxObserver"><code class="xref py py-class docutils literal notranslate"><span class="pre">mindspore.nn.FakeQuantWithMinMaxObserver</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>activation</strong> (<a class="reference internal" href="mindspore.nn.Cell.html#mindspore.nn.Cell" title="mindspore.nn.Cell"><em>Cell</em></a>) – Activation cell.</p></li>
<li><p><strong>ema</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – The exponential Moving Average algorithm updates min and max. Default: False.</p></li>
<li><p><strong>ema_decay</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#float" title="(in Python v3.8)"><em>float</em></a>) – Exponential Moving Average algorithm parameter. Default: 0.999.</p></li>
<li><p><strong>fake_before</strong> (<a class="reference external" href="https://docs.python.org/library/functions.html#bool" title="(in Python v3.8)"><em>bool</em></a>) – Whether add fake quantized operation before activation. Default: False.</p></li>
<li><p><strong>quant_config</strong> (<em>QuantConfig</em>) – Configures the types of quant observer and quant settings of weight and
activation. Note that, QuantConfig is a special namedtuple, which is designed for quantization
and can be generated by <a class="reference internal" href="../mindspore.compression.html#mindspore.compression.quant.create_quant_config" title="mindspore.compression.quant.create_quant_config"><code class="xref py py-func docutils literal notranslate"><span class="pre">mindspore.compression.quant.create_quant_config()</span></code></a> method.
Default: QuantConfig with both items set to default <a class="reference internal" href="mindspore.nn.FakeQuantWithMinMaxObserver.html#mindspore.nn.FakeQuantWithMinMaxObserver" title="mindspore.nn.FakeQuantWithMinMaxObserver"><code class="xref py py-class docutils literal notranslate"><span class="pre">FakeQuantWithMinMaxObserver</span></code></a>.</p></li>
<li><p><strong>quant_dtype</strong> (<a class="reference internal" href="../mindspore.compression.html#mindspore.compression.common.QuantDtype" title="mindspore.compression.common.QuantDtype"><em>QuantDtype</em></a>) – Specifies the FakeQuant datatype. Default: QuantDtype.INT8.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Inputs:</dt><dd><ul class="simple">
<li><p><strong>x</strong> (Tensor) - The input of ActQuant. The input dimension is preferably 2D or 4D.</p></li>
</ul>
</dd>
<dt>Outputs:</dt><dd><p>Tensor, with the same type and shape as the <cite>x</cite>.</p>
</dd>
</dl>
<dl class="field-list simple">
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#TypeError" title="(in Python v3.8)"><strong>TypeError</strong></a> – If <cite>activation</cite> is not an instance of Cell.</p></li>
<li><p><a class="reference external" href="https://docs.python.org/library/exceptions.html#TypeError" title="(in Python v3.8)"><strong>TypeError</strong></a> – If <cite>fake_before</cite> is not a bool.</p></li>
</ul>
</dd>
</dl>
<dl class="simple">
<dt>Supported Platforms:</dt><dd><p><code class="docutils literal notranslate"><span class="pre">Ascend</span></code> <code class="docutils literal notranslate"><span class="pre">GPU</span></code></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">mindspore</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore.compression</span> <span class="kn">import</span> <span class="n">quant</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">mindspore</span> <span class="kn">import</span> <span class="n">Tensor</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">qconfig</span> <span class="o">=</span> <span class="n">quant</span><span class="o">.</span><span class="n">create_quant_config</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">act_quant</span> <span class="o">=</span> <span class="n">nn</span><span class="o">.</span><span class="n">ActQuant</span><span class="p">(</span><span class="n">nn</span><span class="o">.</span><span class="n">ReLU</span><span class="p">(),</span> <span class="n">quant_config</span><span class="o">=</span><span class="n">qconfig</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Tensor</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">]]),</span> <span class="n">mindspore</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">result</span> <span class="o">=</span> <span class="n">act_quant</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="go">[[0.9882355 1.9764705 0.       ]</span>
<span class="go"> [0.        0.        0.       ]]</span>
</pre></div>
</div>
</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
        <a href="mindspore.nn.Conv2dBnAct.html" class="btn btn-neutral float-right" title="mindspore.nn.Conv2dBnAct" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
        <a href="mindspore.nn.MaxPool2d.html" class="btn btn-neutral float-left" title="mindspore.nn.MaxPool2d" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>